成员 "team1Score" 在类型(合约游戏)中进行参数相关查找后未找到或不可见 - Solidity

Member "team1Score" not found or not visible after argument-dependent lookup in type (contract Game) - Solidity

我正在上课,运行遇到了问题。

我正在尝试制作一个函数,从变量 teamNumber 中的团队的角度显示团队得分的差异。

我的问题是,当尝试从其他合同导入变量“team1Score”或“team2Score”时 Game.sol 我收到错误 - 成员“team1Score”未找到或不可见在类型 (contract Game)

中进行依赖于参数的查找之后

这是 Game.sol 合同:

pragma solidity ^0.8.4;

contract Game {
    int public team1Score;
    int public team2Score;

    enum Teams { Team1, Team2 }

    function addScore(Teams teamNumber) external {
        if (teamNumber == Teams.Team1) {
            team1Score +=1;
        } else if (teamNumber == Teams.Team2) {
            team2Score +=1;
        }
    }
}

这里是 Bet.sol 的代码,它引用了 Game.sol。问题在于函数“getScoreDifference”

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "./Game.sol";

contract Bet {
    address public game;



    constructor (address gameContract) {
        game = gameContract;
    }
     
    // calculates the payout of a bet based on the score difference between the two teams
    function calculatePayout(uint amount, int scoreDifference) private pure returns(uint) {
        uint abs = uint(scoreDifference > 0 ? scoreDifference : scoreDifference * -1);  
        uint odds = 2 ** abs;
        if(scoreDifference < 0) {
            return amount + amount / odds;
        }
        return amount + amount * odds;
    }

    function getScoreDifference (Game.Teams x) public view returns (int256){
        if (x == Game.Teams.Team1) {
            return Game.team1Score - Game.team2Score;
        } else if (x == Game.Teams.Team2) {
            return Game.team2Score - Game.team1Score;
        }
    }
}

这个

constructor (address gameContract) {
    game = gameContract;
}

应该是

constructor (address gameContract) {
    game = Game(gameContract);
}

function getScoreDifference (Game.Teams x) public view returns (int256){
    if (x == Game.Teams.Team1) {
        return Game.team1Score - Game.team2Score;
    } else if (x == Game.Teams.Team2) {
        return Game.team2Score - Game.team1Score;
    }
}

应该是

function getScoreDifference (Game.Teams x) public view returns (int256){
        if (x == Game.Teams.Team1) {
            return game.team1Score - game.team2Score;
        } else if (x == Game.Teams.Team2) {
            return game.team2Score - game.team1Score;
        }
    }