Moreover, an object has access to a shared set of class functions. When an object is created, it’s assigned a unique segment of memory space to hold its member variables. Member variables are like states or settings of an object, whereas member functions are mechanism to access and control these settings. ![]() We will add a member variable-ballState-to hold the state information and three member functions-setGold, setSteel, and reset-to access and control the member variable.Ī Java class can have member variables and member functions. Three states are needed: UNCLICKED, GOLD, and STEEL. NOTE: You can select other images but make sure they are not larger than 30×30 pixels (for the cells are 60×60 pixels each), or else the game would not work as planned.īefore adding interaction between the Player class and the GameBall class, we need to add states to the GameBall class. Import another image, ant-with-food.png, by selecting animals->ant-with-food.png. To do so, right click on the Player icon and select Set Image… from the drop-down list. ![]() Now the Player class has been created but we still need to import another image to represent another player. At New class name, enter “Player”, then import the first image, ant.png, by selecting animals->ant.png, and click OK. Right click on the Actor button and select New subclass… from the pop-up menu. To interact with the GameBall objects, we need a class called Player. When the first player clicks at a blank cell, a Gold ball will be placed in that cell when the second player clicks at a blank cell, a Steel ball will be placed in that cell. ![]() When the game starts, all nine cells on the board are blank. This game takes two players, who will take turn clicking. In this lesson, we will add a Player class such that a Player object interacts with GameBall objects in a meaningful way. We also added GameBall objects to the Board object. In the last lesson (Lesson 2), we created the Tic-Tac-Toe Board and GameBall classes.
0 Comments
Leave a Reply. |